"""
单元测试初始化文件
"""

import pytest
import sys
import os
from pathlib import Path

# 添加项目根目录到Python路径
project_root = Path(__file__).parent.parent.parent
sys.path.insert(0, str(project_root))

# 确保可以导入所有需要测试的模块
try:
    from widgets.calendar import models, services, utils, schemas
    from widgets.calendar.models import (
        Calendar, Event, EventRecurrence, EventReminder, 
        EventParticipant, EventTag, CalendarShare, EventComment
    )
    from widgets.calendar.services import (
        CalendarService, EventService, RecurrenceService, 
        ReminderService, ShareService
    )
    from widgets.calendar.utils import (
        DateTimeUtils, RecurrenceUtils, ReminderUtils, 
        ValidationUtils, FormatUtils, Weekday
    )
    from widgets.calendar.schemas import (
        CalendarCreate, CalendarUpdate, EventCreate, EventUpdate,
        EventRecurrenceCreate, EventReminderCreate, CalendarShareCreate,
        EventParticipantCreate, EventTagCreate, EventCommentCreate
    )
    print("✅ 单元测试模块导入成功")
except ImportError as e:
    print(f"❌ 单元测试模块导入失败: {e}")
    sys.exit(1)

# 单元测试配置
def pytest_configure(config):
    """pytest配置"""
    config.addinivalue_line(
        "markers", "asyncio: mark test as async"
    )
    config.addinivalue_line(
        "markers", "slow: mark test as slow running"
    )
    config.addinivalue_line(
        "markers", "integration: mark test as integration test"
    )

# 单元测试固件
@pytest.fixture(scope="session")
def test_db_url():
    """测试数据库URL"""
    return "sqlite:///./test.db"

@pytest.fixture(scope="session")
def test_app():
    """测试应用"""
    from fastapi import FastAPI
    from widgets.calendar import router
    
    app = FastAPI()
    app.include_router(router)
    return app